/**
 * @param {string} s
 * @return {number}
 */
var lengthOfLongestSubstring = function (s) {
  if (s === '') return 0
  let originStr = s.charAt(0)
  let index = 1
  let firstIndex = 0
  let max = 1
  while (index < s.length) {
    const offsetNum = originStr.indexOf(s.charAt(index))
    if (offsetNum !== -1) {
      firstIndex += offsetNum + 1
      originStr = s.substring(firstIndex, index)
    }
    originStr += s.charAt(index)
    index++
    max = Math.max(max, originStr.length)
  }
  return max
}
console.log(lengthOfLongestSubstring('ggububgvfk'))
